<template>
	<view class="pagebody" :style="{ minheight: maxHeight }">
		<view class="topbox">
			<view class=" justify-between align-center">
				<view class=" flex-row align-center">
					<image @click="backpage" src="@/static/images/login/leftjt.png" alt=""
						style="width: 48rpx;height: 48rpx;"></image>
				</view>
				<view class="bgfff searchbox justify-between align-center">
					<input class="searchinput" v-model="keyword" type="text" placeholder="搜索提醒"
						:placeholderStyle="placeholderStyle" />
					<image @click="searchuse" src="@/static/images/home/searchimg.png"
						style="width:48rpx ;height:48rpx ;"></image>
				</view>
			</view>
		</view>
		<view class="">
			<view v-for="(item,index) in reminderlist" :key="index" class="mb16"
				style="background: #FFFFFF;border-radius: 32rpx;">
				<view class="justify-between align-center"
					style="height: 100rpx;border-bottom: 1rpx solid #D7DDDC;padding: 0 24rpx;">
					<view class=" flex-row align-center">
						<view class=""
							style="margin-right:8rpx;width: 8rpx;height: 32rpx;background: #00D9B2;border-radius: 8rpx;">
						</view>
						<view class="color303b39 fz36 fwbold lineclamp1">
							{{item.remindTitle}}
						</view>
					</view>
					<view class="flex-row">
						<image @click="deleteremind(item.id)" src="../../static/images/mine/usedrugdelete.png"
							style="width: 30rpx;height: 36rpx;" mode=""></image>
					</view>
				</view>
				<view class="flex-row justify-between align-center" style="padding: 32rpx 24rpx;">
					<view @click="toedit(item)" class=" " style="flex: 1;">
						<view class="flex-row mt16">
							<view class="color303b39 fwbold lineclamp2" style="margin-left: 8rpx;">
								{{item.remindContent}}
							</view>
						</view>
						<view class="flex-row mt16">
							<view class="" style="margin-left: 8rpx; color: #7E8987;">
								{{item.createTime}}
							</view>
						</view>
					</view>
					<view class="">
						<switch :checked="item.state==1?true:false" @change="changeState(item)" color="#00D9B2"
							style="transform:scale(0.7)" />
					</view>

				</view>
			</view>
		</view>

		<view class="addcase align-center justify-center" @click="toadd">
			<span style="font-size: 56rpx;">+</span> 新增提醒
		</view>
		<u-modal v-model="delshow" :show-cancel-button="true" :confirm-text="'删除'" @confirm="delpost"
			@cancel="nodelpost" :cancel-text="'取消'" content="是否删除该提醒？"></u-modal>
		<u-toast ref="uToast" />
		<!-- <FixedFoot :typeid="4"></FixedFoot> -->
	</view>
</template>

<script>
	import {
		reminderList,
		delreminder,
		editreminder
	} from '@/api/api.js'
	// import FixedFoot from '../../layouts/fixedfoot.vue';
	export default {
		components: {
			// FixedFoot
		},
		onLoad() {
			// 获得屏幕最大高度
			let systemInfo = uni.getSystemInfoSync();
			this.maxHeight = systemInfo.windowHeight + "px";
		},


		data() {
			return {
				socket: null,
				placeholderStyle: "color:#7E8987;font-size:28rpx;font-weight: 400;",
				reminderlist: [],
				delshow: false,
				delid: null,
				keyword: '',
				maxHeight: '',

			}
		},
		watch: {},
		onShow() {
			this.getreminderlist()
		},
		methods: {
			searchuse() {
				let data = {
					remindTitle: this.keyword
				}
				reminderList(data).then(res => {
					this.reminderlist = res.rows
				})


			},
			deleteremind(id) {
				this.delid = id
				this.delshow = true

			},
			delpost() {
				delreminder(this.delid).then(res => {
					this.$refs.uToast.show({
						title: '删除成功',
						type: 'success',
					})
					this.getreminderlist()
				})
			},
			nodelpost() {
				this.delid = null
			},
			toedit(item) {
				uni.navigateTo({
					url: '/pages/mine/addusedrug?id=' + item.id
				})
			},
			backpage() {
				uni.navigateBack({
					delta: 1,

				});
			},
			getreminderlist() {
				let data = {}
				reminderList(data).then(res => {
					this.reminderlist = res.rows
				})
			},
			toadd() {
				uni.navigateTo({
					url: '/pages/mine/addusedrug'
				})
			},
			changeState(item) {
				let newstate = item.state == 1 ? 0 : 1
				item.state = newstate
				
				editreminder(item).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
					})
					// setTimeout(()=>{
					// 	uni.navigateTo({
					// 	    url: '/pages/mine/usedruglist',
					// 	})
					// },1000)
					// console.log(111)
					
				})

			},

		},
		// 1.长度为8-20个字符 2.必须包含大小写字母和数字 3.可以使用特殊字符!@#$%^&* 4.不能包含空格
	}
</script>

<style lang="scss" scoped>
	.pagebody {
		padding-bottom: 136rpx;
		background: #F0F6F5;

		.topbox {
			height: 128rpx;
			background: linear-gradient(180deg, rgba(0, 217, 178, 0.2) 0%, rgba(0, 217, 178, 0) 100%);
			padding: 20rpx 24rpx;

			.searchbox {
				width: 630rpx;
				height: 60rpx;
				background: #FFFFFF;
				border-radius: 60rpx;
				border: 2rpx solid rgba(0, 217, 178, 0.2);
				padding: 0 24rpx;

				.searchinput {
					font-size: 28rpx
				}

			}
		}

		.addcase {
			margin-top: 179rpx;
			margin-left: 41rpx;
			width: 668rpx;
			height: 98rpx;
			background: #00D9B2;
			border-radius: 98rpx;
			color: #FFFFFF;
			font-size: 36rpx;
			position: fixed;
			bottom: 25px;
		}
	}
</style>